import requests

# 图片url
url = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1604972728&di=877490cd53b4225740a3ceb46c559db7&imgtype=jpg&er=1&src=http%3A%2F%2Fpic.jj20.com%2Fup%2Fallimg%2Fmx10%2F010120214511%2F200101214511-4.jpg'
# 发送请求
r = requests.get(url=url, stream=True)
reponse_body_lenth = int(r.headers.get('Content-Length'))
print('长度：', reponse_body_lenth)
with open('iu.png', 'wb') as iu:
    writh_lenght = 0
    for chunk in r.iter_content(chunk_size=100):
        writh_lenght += iu.write(chunk)  # write的返回值为写入到文件内容的多少
        print('下载进度：%02.6f%%' % (100 * writh_lenght / reponse_body_lenth))
